import { defHttp } from '/@/utils/http/axios';
import {
  PackagedParams,
  TaskEncasementParam,
  ReduceCodeHandleParam,
  ValidateParam,
} from './model/water-box';

enum Api {
  GetWaterList = '/jd/task/boxedWaterMeter',
  GetPackageWaterList = '/jd/task/getBox',
  GetStandardList = '/jd/task/unBoxedWaterMeter',
  GetDisqualification = '/jd/task/unqualifiedWaterMeter',
  GetPendingVerification = '/jd/task/unDetect',
  GetRecheckList = '/jd/task/recheckWaterMeter',
  GetCountResult = `/jd/task/countResult`,
  GetBoxQrCodeMsg = '/jd/meter/boxQrCodeMsg',
  GetTaskApply = '/jd/task/getTaskApply',
  GetWaterMeterByCode = '/jd/task/waterMeterById',
  GetTaskEncasement = '/jd/task/encasement',
  GetCodeEncasementNum = '/jd/task/codeEncasementNum',
  GetRecheckWaterMeterHandle = '/jd/task/recheckWaterMeterHandle',
  GetRecheckWaterMeterByCode = '/jd/task/recheckWaterMeterByCode',
  MergeData = '/jd/task/recheckMerge',
  GetRecodIdList = '/jd/task/recheckWaterMeterById',
  WaterReturnTable = '/jd/task/retreatWaterMeter',
  TaskErroneous = '/jd/task/erroneous',
  RetreatWaterMeterList = '/jd/task/retreatWaterMeterList',
  GetWaterMeterStatus = '/jd/meter/waterMeterStatus',
  RefreshData = '/jd/task/refreshData',
  ReduceCodeHandle = '/jd/task/reduceCodeHandle',
  FileDownLoad = '/jd/task/fileDownLoad',
  GenerateFile = '/jd/meter/generateOriginalRecord',
  TaskValidateAudit = '/jd/task/validateAudit',
  TaskValidateApply = '/jd/task/validate',
  TaskAutoEncasement = '/jd/task/autoEncasement',
  DeleteBox = '/jd/task/deleteBox',
  GetDataByCert = '/jd/task/getDataByCert',
}
// 获取已编箱列表
export const getPackagedList = (params: PackagedParams) => {
  const { taskId } = params;

  return defHttp.post<any>({
    url: `${Api.GetPackageWaterList}/${taskId}`,
    params,
  });
};

// 获取已编箱水表
export const getPackagedWaterList = (params: PackagedParams) => {
  const { taskId } = params;

  const url = `/${taskId}`;
  return defHttp.post<any>({
    url: Api.GetWaterList + url,
    params,
  });
};

// 合格未编箱
export const getStandardList = (params: PackagedParams) => {
  const { taskId } = params;
  const url = `/${taskId}`;

  return defHttp.post<any>({
    url: Api.GetStandardList + url,
    params,
  });
};

// 不合格水表
export const getDisqualification = (params: PackagedParams) => {
  const { taskId } = params;
  const url = `/${taskId}`;

  return defHttp.post<any>({
    url: Api.GetDisqualification + url,
    params,
  });
};

// 待检定水表 /task/unDetect
export const getPendingVerification = (params: PackagedParams) => {
  const { taskId } = params;
  const url = `/${taskId}`;

  return defHttp.post<any>({
    url: Api.GetPendingVerification + url,
    params,
  });
};
export const getRecheckList = (params: PackagedParams) => {
  const { taskId } = params;
  const url = `/${taskId}`;

  return defHttp.post<any>({
    url: Api.GetRecheckList + url,
    params,
  });
};

// 检定结果统计
export const getCountResult = (params: PackagedParams) => {
  const { taskId } = params;
  const url = `/${taskId}`;
  return defHttp.get<any>({
    url: Api.GetCountResult + url,
  });
};

// 获取二维码数据
export const getBoxQrCodeMsg = (boxId) =>
  defHttp.get<any>({
    url: Api.GetBoxQrCodeMsg + '/' + boxId,
  });

// 获取委托单详情
export const getTaskApply = (taskId) =>
  defHttp.get<any>({
    url: Api.GetTaskApply + '/' + taskId,
  });
// 根据表码查看详情
export const getWaterMeterByCode = (waterMeterCode) =>
  defHttp.get<any>({
    url: Api.GetWaterMeterByCode + '/' + waterMeterCode,
  });

// 手动编箱 GetTaskEncasement
export const getTaskEncasement = (params: TaskEncasementParam) => {
  const { taskId, waterMeterCodes } = params;
  return defHttp.post<any>({
    url: Api.GetTaskEncasement + '/' + taskId,
    params: waterMeterCodes,
  });
};

// 获取编箱数量
export const getCodeEncasementNum = (taskId: string) =>
  defHttp.get<any>({
    url: Api.GetCodeEncasementNum + '/' + taskId,
  });

// 复检
export const getRecheckWaterMeterHandle = (waterMeterCode: string) =>
  defHttp.post<any>({
    url: Api.GetRecheckWaterMeterHandle + '/' + waterMeterCode,
  });
// 根据表码获取复检数据
export const getRecheckWaterMeterByCode = (params: { waterMeterCode: string; taskId: string }) =>
  defHttp.get<any>({
    url: Api.GetRecheckWaterMeterByCode + '/' + params.waterMeterCode + '/' + params.taskId,
  });

// 最终数据合并
export const submitMergeData = (params: { data: object; taskId: string }) => {
  return defHttp.post<any>({
    url: `${Api.MergeData}/${params.taskId}`,
    params: params.data,
  });
};

// 根据复检记录id获取详情
export const getRecodIdList = (params: { resultId: string; taskId: string }) =>
  defHttp.get<any>({
    url: Api.GetRecodIdList + '/' + params.resultId + '/' + params.taskId,
  });

// 退表
export const submitWaterReturnTable = (params: { waterCodesArray: string[]; taskId: string }) =>
  defHttp.post<any>({
    url: Api.WaterReturnTable + '/' + params.taskId,
    params: params.waterCodesArray,
  });

// 误判
export const submitTaskErroneous = (params: { waterMeterId: string; taskId: string }) =>
  defHttp.post<any>({
    url: Api.TaskErroneous + '/' + params.waterMeterId + '/' + params.taskId,
  });

// 退表列表
export const getRetreatWaterMeterList = (params: PackagedParams) =>
  defHttp.post<any>({
    url: Api.RetreatWaterMeterList + '/' + params.taskId,
    params: {
      current: params.current,
      size: params.size,
    },
  });
// 水表明细 时间轴 GetWaterMeterStatus
export const getWaterMeterStatus = (waterMeterId: string) =>
  defHttp.get<any>({
    url: Api.GetWaterMeterStatus + '/' + waterMeterId,
  });
// 手动调用接口同步第三方接口给后端  RefreshData
export const submitRefreshData = (taskId: string) =>
  defHttp.post<any>({
    url: Api.RefreshData + '/' + taskId,
  });
// 原始记录单、证书文件下载
export const jdFileDown = (params: { path: string }) =>
  defHttp.post<any>(
    {
      url: Api.FileDownLoad,
      responseType: 'arraybuffer',
      params,
    },
    { isReturnNativeResponse: true },
  );

// 申请单扫码新增
export const submitReduceCodeHandle = (params: ReduceCodeHandleParam) =>
  defHttp.post<any>({
    url: `${Api.ReduceCodeHandle}/${params.taskId}/${params.applyId}`,
    params: params.waterMeterCodes,
  });

// 生成记录单 GenerateFile
export const generateFile = (waterMeterId: string) =>
  defHttp.get<any>({
    url: `${Api.GenerateFile}/${waterMeterId}`,
  });
// 校验审核数据
export const taskValidateAudit = (params: ValidateParam) =>
  defHttp.post<any>({
    url: `${Api.TaskValidateAudit}/${params.taskId}/${params.type}`,
    params: params.waterCodes,
  });
//校验委托单的发起
export const taskValidateApply = (applyId: string) =>
  defHttp.post<any>({
    url: `${Api.TaskValidateApply}/${applyId}`,
  });
// 自动编箱
export const setTaskAutoEncasement = (taskId: string) =>
  defHttp.post<any>({
    url: `${Api.TaskAutoEncasement}/${taskId}`,
  });
// 删除装箱数据
export const deleteBox = (params: { taskId: string; boxId: string; boxCode: string }) =>
  defHttp.post<any>({
    url: `${Api.DeleteBox}/${params.taskId}/${params.boxId}/${params.boxCode}`,
  });
// 扫码跳转页面数据获取 /task/getDataByCert/
export const getDataByCertCode = (code: string) =>
  defHttp.get<any>({
    url: Api.GetDataByCert + '/' + code,
  });
